package collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 * 泛型的演示
 * jdk 1.5之后才支持泛型
 * 泛型也称之为 参数化类型  允许我们在使用一个类中，
 * 传入某个类型来规定其内部的属性、方法的返回值类型、方法的参数类型
 */
public class CollectionDemoFive {
    public static void main(String[] args) {
        ArrayList<String > list = new ArrayList<>();
        list.add("hello");
        list.add("world");
        for (int i = 0; i < list.size(); i++){
            System.out.println(list.get(i));
        }

        for (String string : list) {
            System.out.println(string);
        }
        Collection<Point> collection = new ArrayList<>();
        collection.add(new Point(2, 6));
        collection.add(new Point(3, 7));
        collection.add(new Point(4, 8));
        collection.add(new Point(5, 9));
        collection.add(new Point(6, 10));
        System.out.println("!!!!!!!!!!!!!");
        System.out.println(collection.size());
        for (Point point : collection) {
            System.out.println(point.getX() + "," + point.getY());
        }
//迭代器
        Iterator<String> it = list.iterator();//创建迭代器
        while (it.hasNext()) {//判断是否有下一个元素
            String str = it.next();//获取元素

            if ("world".equals(str)) {//判断元素是否为world
                it.remove();//删除元素
            }
        }
        System.out.println(list);
    }
}
